package com.bytedance.modulizeandrouter

import android.content.Intent
import android.os.Bundle
import android.widget.Button
import android.widget.Toast
import androidx.activity.result.contract.ActivityResultContract
import androidx.activity.result.contract.ActivityResultContracts
import com.alibaba.android.arouter.facade.annotation.Route
import com.bytedance.common.base.BaseActivity
import com.bytedance.common.constants.RouterPathConstants

@Route(path = RouterPathConstants.MAIN_ACTIVITY_PATH)
class MainActivity : BaseActivity() {
    private lateinit var goToTestPage: Button
    companion object {
        const val REQUEST_CODE = 100
        const val RESULT_CODE = 101
    }
    override fun getLayoutId() = R.layout.activity_main

    override fun initData() {
        goToTestPage = findViewById(R.id.go_to_test_page)
    }

    override fun initListener() {
        goToTestPage.setOnClickListener {
//            open(RouterPathConstants.PERSONAL_ACTIVITY_PATH){
//                withString("name","fuck")
//                withInt("age",12)
//            }
            startActivityForResult(Intent(this,TestActivity::class.java), REQUEST_CODE)

//            val startActivity = registerForActivityResult(ActivityResultContracts.StartActivityForResult()){
//                if (it.resultCode == RESULT_CODE) {
//                    Toast.makeText(this,"回调回来了",Toast.LENGTH_SHORT).show()
//                }
//            }
//            startActivity.launch(Intent(this,TestActivity::class.java))
        }
    }


    override fun startActivityForResult(intent: Intent?, requestCode: Int, options: Bundle?) {
        super.startActivityForResult(intent, requestCode, options)
        if (requestCode == REQUEST_CODE ) {
            Toast.makeText(this,"回调回来了",Toast.LENGTH_SHORT).show()
        }
    }

}